package com.bawei.module_service.ui

import android.util.Log
import androidx.fragment.app.viewModels
import androidx.recyclerview.widget.GridLayoutManager
import com.alibaba.android.arouter.launcher.ARouter
import com.bawei.lib_common.Router
import com.bawei.lib_common.base.BaseFragment
import com.bawei.lib_common.base.BaseViewModel
import com.bawei.module_service.R
import com.bawei.module_service.adapter.ServiceAdapter
import com.bawei.module_service.databinding.FragmentServiceBinding
import com.bawei.module_service.http.ServiceViewModel
import com.bawei.module_service.model.ServiceItemModel
import dagger.hilt.android.AndroidEntryPoint

@AndroidEntryPoint
class ServiceFragment : BaseFragment<BaseViewModel,FragmentServiceBinding>() {
    override val mLayoutResId: Int
        get() = R.layout.fragment_service
    // 创建ViewModel
    private val mViewModel:ServiceViewModel by viewModels()

    //创建适配器
    val mAdapter:ServiceAdapter by lazy {
        ServiceAdapter()
    }
    //初始化view
    override fun initView() {
        super.initView()
        mViewModel.initServiceItemList()
        initAdapter()
        mAdapter.setOnItemClickListener(object : ServiceAdapter.OnItemClickListener{
            override fun clickListener(
                item: ServiceItemModel,
                position: Int
            ) {
                when(item.title){
                    "车辆管理"->{

                    }
                    "车位管理"->{
                        ARouter.getInstance().build(Router.AREA_PAGE).navigation()
                    }
                    "访客管理"->{
                        ARouter.getInstance().build(Router.VISITOR_MANAGER_PAGE).navigation()
                    }
                    "维修管理"->{
                        ARouter.getInstance().build(Router.MAINTAIN_PAGE).navigation()
                    }
                    "公告管理"->{
                        ARouter.getInstance().build(Router.NEWS_PAGE).navigation()
                    }
                    "考勤管理"->{
                        ARouter.getInstance().build(Router.SIGN_PAGE).navigation()
                    }
                    "即时通讯"->{
                        //无
                    }
                    "设备设置"->{
                        ARouter.getInstance().build(Router.DEVICES_PAGE).navigation()
                    }
                    "房源信息"->{
                        ARouter.getInstance().build(Router.HOUSE_PAGE).navigation()
                    }
                    "物业报修"->{
                        ARouter.getInstance().build(Router.REPAIR_PAGE).navigation()
                    }
                    "巡检管理"->{
                        ARouter.getInstance().build(Router.POLLING_PAGE).navigation()
                    }
                    "月卡会员"->{
                        ARouter.getInstance().build(Router.VIP_PAGE).navigation()
                    }
                }
            }

        })

    }
    //获取数据
    override fun initData() {

    }
    //实现网络接口
    override fun initListener() {

    }


    private fun initAdapter() {
        Log.d("GZY", "initAdapter: "+mViewModel.ServiceLists.size)
        mAdapter.setData(mViewModel.ServiceLists)
        mBinding.serciceRv.layoutManager=GridLayoutManager(context,3)
        mBinding.serciceRv.adapter=mAdapter

    }


}